
#ifndef PEERLOGER_H_

#define PEERLOGER_H_

#include <stdio.h>
#include <stdarg.h>

#include "common.h"
#include "object.h"

#define PEERLOGER_MAX_FILE_NAME_LEN 1024


class PeerLoger : public Object{
    public:
        ~PeerLoger();

		static bool create();
		static void destroy();
        static PeerLoger& instance();

		bool init();

        void logScheduler(int level, const char* fmt, ...);
        void logTrans(int level, const char* fmt, ...);
        void logDebug(int level, const char* fmt, ...);
        void logError(int level, const char* fmt, ...);
		void logResult(int level, const char* fmt, ...);
		void logChord(int level, const char* fmt, ...);

        void flush();

        int command(int argc, const char*const* argv);
    protected:
        PeerLoger();
        void log( const char*, const char* fmt, va_list);

		bool ensureFileSize();
		void nextFileName();
    protected:
        static PeerLoger *instance_;
        FILE *file_;
        bool to_screen_;
		char file_name_[PEERLOGER_MAX_FILE_NAME_LEN];
		char base_file_name_[PEERLOGER_MAX_FILE_NAME_LEN];

		int file_name_counter_;

        //switches
		bool log_sch_; 
		bool log_trans_;
        bool log_debug_;
        bool log_error_;
		bool log_result_;
		bool log_chord_;

        bool auto_flush_;
};

#endif /* PEERLOGER_H_ */

